<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class addUservalidata extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username'              => 'required|min:2|max:16',
            'password'              => 'required|confirmed|min:6',
            'password_confirmation' => 'required',
            'sex'                   => 'required',
            'phone'                 => ['required', 'unique:shop_home_users','regex:/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/u'],
        ];
    }

    public function messages()
    {
        return [
            'username.required'              => '用户名不能为空',
            'phone.required'                 => '手机号码不能为空',
            'phone.unique'                   => '手机号已注册',
            'username.min'                   => '用户名不能小于2',
            'username.max'                   => '用户名不能大于16',
            'password.required'              => '密码不能为空',
            'password.min'                   => '密码不能少于6位',
            'password.confirmed'             => '两次密码内容不相同',
            'sex'                            => '请选择性别',
            'phone.regex'                    => '手机号码不正确',
            'password_confirmation.required' => '确认密码不能为空',
            'password_confirmation.min'      => '密码不能少于6位',
        ];
    }
}
